package 力扣日常刷题.木22二月.第04天210;

/**
 * @author 帅小伙
 * @date 2022/2/10
 * @description
 */
public class Demo32JZ调整数组顺序使奇数位于偶数前面 {


    public int[] exchange(int[] nums) {
        int l = 0, r = nums.length - 1;
        int n = nums.length - 1;
        while (l < r) {
            while (l < n && nums[l] % 2 == 1) l++;
            while (r > 0 && nums[r] % 2 == 0) r--;
            if(r > l){
                int t =nums[r];
                nums[r]  = nums[l];
                nums[l] = t;
            }
        }
        return nums;
    }

}
